package ngat.oss.simulation.test;

import ngat.util.*;
import ngat.phase2.*;
import ngat.oss.simulation.*;
import java.io.*;
import java.rmi.*;
import java.util.*;

public class Phase2GenLoad {
    
    /** Test Load a P2 model.*/
    public static void main(String args[]) {
	
        try {
	    
	    ConfigurationProperties cfg = CommandTokenizer.use("--").parse(args);
	    
	    File loadFile = new File(cfg.getProperty("load"));
	    
            Phase2ModelGenerator gen = new Phase2ModelGenerator();
	    gen.loadPhase2Model(loadFile);

	    String modelName = gen.getModelName();
	    long   modelTime = gen.getModelDate();

            Phase2Model model = gen.getPhase2Model();

            Naming.rebind("rmi://localhost/"+model.getRootName()+"_Phase2ModelProvider", gen);

            System.err.println("PhaseModelGenerator provider bound to registry: Model: "+modelName+
			       ", Root: "+model.getRootName()+
			       " Valid for: "+ScheduleSimulator.sdf.format(new Date(modelTime)));

            // busy wait to keep alive
            while (true) {
                try{Thread.sleep(60000L);} catch (Exception e) {}
            }

        } catch (Exception e) {
            e.printStackTrace();
	    System.err.println("Usage: Phase2GenLoad --load <file>");
        }

    }
}
